home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1997 December
/
MACPOWER-1997-12.ISO.7z
/
MACPOWER-1997-12.ISO
/
AMUG
/
MAC OS 8
/
cmm-framework-10.sit
/
Trygve's CMM Framework 1.0
/
PluginTemplate
/
Plugin.cp
< prev
next >
Wrap
Text File
|
1997-08-28
|
9KB
|
224 lines
//
// Copyright ゥ1997 by Trygve Isaacson. All Rights Reserved.
//
// Additional Restrictions:
//
// Permission granted to:
// - Compile this source code.
// - Modify this source code, but not to remove this copyright information.
// - Freely distribute the compiled object form of this source code, and any
// modifications you make, in your programs.
//
// Permission NOT granted to:
// - Redistribute modified versions of this source code.
//
// You grant Trygve Isaacson one single-user license to your plugins based
// on this source code, and notify him at:
// trygve@bombaydigital.com
//
#include "Plugin.h"
#undef Inherited
#define Inherited PluginBase
#define kBeepCommand 0
Plugin::Plugin()
{
}
Plugin::~Plugin()
{
}
UInt32 Plugin::GetPluginDataTypes(OSType** pluginTypesArrayPtr, Boolean* lookInLists)
{
// You only have to override this if you process a data type other than typeFSS. The
// base class fills in a single array element for typeFSS.
// EXAMPLE OVERRIDE:
// const UInt32 kMyNumTypes = 2; // I have two data types I process.
// *pluginTypesArrayPtr = (OSType*) ::NewPtr(kMyNumTypes * sizeof(OSType));
// *pluginTypesArrayPtr[0] = typeFSS; // I can process files.
// *pluginTypesArrayPtr[1] = typeChar; // I can process raw text.
// *lookInLists = true;
// return kMyNumTypes;
const UInt32 kMyNumTypes = 1;
*pluginTypesArrayPtr = (OSType*) ::NewPtr(kMyNumTypes * sizeof(OSType));
*pluginTypesArrayPtr[0] = typeFSS; // I can process file specs.
*lookInLists = true;
return kMyNumTypes;
}
Boolean Plugin::AddMultiDataTypeCommand(AEDescList* commandList, UInt32 /*numDataTypes*/, OSType* /*dataTypesArray*/, UInt32 numDataTypesFound)
{
// You will normally use this override, assuming you use a given command for several
// data types, or your one-and-only data type.
// EXAMPLE OVERRIDE:
// Suppose you have 1 command that you use if ANY desired types was found:
// if (numDataTypesFound > 0)
// this->AddCMMCommand(commandList, "¥pDo My Stuff", kDoMyStuffCommand);
// return true; // true means do NOT call AddDataTypeCommand for individual data types
// If you don't override this message, or if you return false from it, you must
// override AddDataTypeCommand, which is the next function below.
if (numDataTypesFound > 0)
this->AddCommand(commandList, "¥pBeep", kBeepCommand);
return true; // true means do NOT call AddDataTypeCommand for individual data types
}
void Plugin::AddDataTypeCommand(AEDescList* /*commandList*/, OSType /*dataType*/)
{
// You will need to use this override if you operate on multiple data types, and you
// don't use the same command for all types. You will use this override to add
// the command(s) that apply to the supplied data type, or to remember (through a
// Plugin class instance variable) that the supplied type was found, so that you
// can add the commands at the end of the Examine phase.
// EXAMPLE OVERRIDE:
// Suppose you use different commands depending on what's selected, for example,
// you have one command for operating on FSSpec's, and a different command for
// TEXT data in the AEDesc.
// if (dataType == typeFSS)
// this->AddCMMCommand(commandList, "¥pBash File", kBashCommand);
// else if (dataType == typeChar)
// this->AddCMMCommand(commandList, "¥pMunge Text", kMungeTextCommand);
// If you don't override this message, you must override AddMultiDataTypeCommand,
// which is the previous function above.
}
OSType Plugin::GetCoercionTypeForCommand(SInt32 /*commandID*/)
{
// You only have to override this if you process a data type other than typeFSS. The
// base class returns typeFSS.
// EXAMPLE OVERRIDE:
// You have to override this to tell the base class how to coerce that AEDesc
// data. If you only process a single type, return it. Otherwise, check the
// commandID to see what command you are dealing with. Suppose you have a couple
// of data types as shown in the examples above:
// if (commandID == kBashCommand)
// return typeFSS;
// else //if (commandID == kMungeTextCommand)
// return typeChar;
return typeFSS;
}
OSStatus Plugin::ProcessSelectionItem(AEDesc* /*coercedDescriptor*/, SInt32 /*commandID*/)
{
// If you process non-typeFSS data, this is where you get to do your work. If you
// process typeFSS data, you can use the "AlterXXXXX" methods instead, which get
// called by the base class after some file management has been done for you.
// EXAMPLE OVERRIDE:
// If you're doing FSSpec's and not other AEDesc data, you don't have to override
// this. But if you do non-FSSpec data, this is where you get each item and
// process it.
::SysBeep(5);
return noErr;
}
Boolean Plugin::IsDesiredFSSpec(const FSSpec* aFileSpec, SInt32 /*commandID*/, Boolean /*isExaminePhase*/)
{
// If you are processing typeFSS data, but only want certain files, you need to
// override this method. If you depend only the file type/creator being right,
// you can call PluginBase::IsSpecificCreatorType to find out. If you depend on
// other file attributes, you'll have to do something like GetFInfo on the file.
// The isExaminePhase parameter tells you whether the file is being checked during
// the menu building (examination) phase or the command processing phase; you might
// use it in special cases.
// Don't forget, folders are also FSSpec's. There's a method PluginBase::IsFolder
// that can be used to check for folders.
// EXAMPLE OVERRIDE:
// Suppose I process FSSpecs, but only text files and applications, and also
// suppose that I don't want to spend time checking this while examining files,
// only when actually processing files. In other words, during the examine phase,
// I'll accept any FSSpec in the selection as reason to add my command to the menu,
// but during the execution phase, I'll skip any inappropriate files.
// return ((! isExaminePhase) &&
// (this->IsSpecificCreatorType(aFileSpec, '****', 'TEXT') ||
// this->IsSpecificCreatorType(aFileSpec, '****', 'APPL'));
// In this example, we skip folders and just do files.
/*
Str255 bug = "¥pCreator[xxxx], Type[xxxx]";
FInfo info;
(void) ::FSpGetFInfo(aFileSpec, &info);
::BlockMove(&info.fdCreator, &bug[9], 4);
::BlockMove(&info.fdType, &bug[21], 4);
::DebugStr(bug);
*/
return ! this->IsSpecificCreatorType(aFileSpec, '****', 'TEXT');
}
Boolean Plugin::ModifiesFileInfo(FSSpec* /*aFile*/, SInt32 /*commandID*/)
{
// You only have to override this if you return true. This indicates that
// you will modify the FInfo of the file, so the FInfo is gotten and set,
// and you just have to tweak the contents of the FInfo in your override
// of AlterFileInfo.
return true;
}
Boolean Plugin::ModifiesDataFork(FSSpec* /*aFile*/, SInt32 /*commandID*/)
{
// You only have to override this if you return true. This indicates that
// you will modify the data fork of the file, so the temp file is created
// and opened for you, etc. In this example we are just modifying the FInfo.
return false;
}
Boolean Plugin::ModifiesResourceFork(FSSpec* /*aFile*/, SInt32 /*commandID*/)
{
// You only have to override this if you return true. This indicates that
// you will modify the resource fork of the file, so the temp file is created
// and opened for you, etc. In this example we are just modifying the FInfo.
return false;
}
Boolean Plugin::AlterFileInfo(FInfo* /*fileInfo*/, FSSpec* /*aFile*/, SInt32 /*commandID*/)
{
// You will only override this if you return true for ModifiesFileInfo. You are
// given the existing FInfo of the file. You modify it and return true. If for
// some reason you don't actually modify it, return false, so that it is not
// written back to disk.
return false;
}
OSStatus Plugin::AlterDataFork(SInt16 /*origFileRefnum*/, SInt16 /*tempFileRefnum*/, SInt32 /*commandID*/)
{
// Since our overrides above indicate that we don't touch the data fork, this
// override won't actually be called, and isn't needed. But if you indicate that
// you modify the data fork, this is called for you to FSRead data from the
// origFileRefnum (the original file), process it, and FSWrite it to the
// tempFileRefnum (the temp file). If anything goes wrong, return an error result
// and everything will be cleaned up so the original file is left untouched. If
// everything succeeds, the temp file and the original are exchanged, then the
// original is deleted.
return noErr;
}
OSStatus Plugin::AlterResourceFork(SInt16 /*origFileRefnum*/, SInt16 /*tempFileRefnum*/, SInt32 /*commandID*/)
{
// Since our overrides above indicate that we don't touch the resource fork, this
// override won't actually be called, and isn't needed. But if you indicate that
// you modify the resource fork, this is called for you to get resources from the
// origFileRefnum (the original file), do your stuff, and write resources to the
// tempFileRefnum (the temp file). Make sure you call UseResFile as appropriate.
// If anything goes wrong, return an error result and everything will be cleaned
// up so the original file is left untouched. If everything succeeds, the temp file
// and the original are exchanged, then the original is deleted.
return noErr;
}